#include"dao.h"

void load_data(List* list,const char* file,size_t size)
{
	FILE* frp = fopen(file,"r+");
	if(NULL == frp)
	{
		puts("文件加载失败!\n");
		return ;
	}
	while(true)
	{
		void* ptr = malloc(size);
		if(1 > fread(ptr,size,1,frp))
		{
			free(ptr);
			return ;
		}
		add_tail(list,ptr);
	}
	fclose(frp);
	
}

void save_data(List* list,const char* file,size_t size)
{
	FILE* fwp = fopen(file,"w+");
	if(NULL == fwp)
	{
		puts("文件保存失败!\n");
		return ;
	}
	for(Node* node = list->head;node!=NULL;node= node->next)
	{
		fwrite(node->ptr,size,1,fwp);
	}
	fclose(fwp);

}
